{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "pd.set_option('display.max_rows', None)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to identify the column(s) of a given DataFrame which have at least one missing value.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50  2012-10-05         3002       5002.0\n",
       "1       NaN     270.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26         NaN         3001       5001.0\n",
       "3   70004.0     110.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50  2012-09-10         3002       5002.0\n",
       "5   70005.0    2400.60  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43  2012-10-10         3004          NaN\n",
       "8   70003.0    2480.40  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,270.65,65.26,110.5,948.5,2400.6,5760,1983.43,2480.4,250.45, 75.29,3045.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Identify the columns which have at least one missing value:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "ord_no          True\n",
       "purch_amt      False\n",
       "ord_date        True\n",
       "customer_id    False\n",
       "salesman_id     True\n",
       "dtype: bool"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nIdentify the columns which have at least one missing value:\")\n",
    "df.isna().any()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to count the number of missing values in each column of a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ord_no         4\n",
       "purch_amt      0\n",
       "ord_date       1\n",
       "customer_id    0\n",
       "salesman_id    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.isna().sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to find and replace the missing values in a given DataFrame which do not have any valuable information.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001</td>\n",
       "      <td>150.5</td>\n",
       "      <td>?</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>?</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004</td>\n",
       "      <td>110.5</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>5001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.5</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005</td>\n",
       "      <td>2400.6</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>--</td>\n",
       "      <td>5760</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010</td>\n",
       "      <td>?</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>?</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003</td>\n",
       "      <td>12.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>--</td>\n",
       "      <td>5003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012</td>\n",
       "      <td>2480.4</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013</td>\n",
       "      <td>3045.6</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>--</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ord_no purch_amt    ord_date customer_id salesman_id\n",
       "0   70001     150.5           ?        3002        5002\n",
       "1     NaN    270.65  2012-09-10        3001        5003\n",
       "2   70002     65.26         NaN        3001           ?\n",
       "3   70004     110.5  2012-08-17        3003        5001\n",
       "4     NaN     948.5  2012-09-10        3002         NaN\n",
       "5   70005    2400.6  2012-07-27        3001        5002\n",
       "6      --      5760  2012-09-10        3001        5001\n",
       "7   70010         ?  2012-10-10        3004           ?\n",
       "8   70003     12.43  2012-10-10          --        5003\n",
       "9   70012    2480.4  2012-06-27        3002        5002\n",
       "10    NaN    250.45  2012-08-17        3001        5003\n",
       "11  70013    3045.6  2012-04-25        3001          --"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,\"--\",70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,270.65,65.26,110.5,948.5,2400.6,5760,\"?\",12.43,2480.4,250.45, 3045.6],\n",
    "'ord_date': ['?','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,\"--\",3002,3001,3001],\n",
    "'salesman_id':[5002,5003,\"?\",5001,np.nan,5002,5001,\"?\",5003,5002,5003,\"--\"]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3002.0</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003.0</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>12.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>NaN</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002.0</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001.0</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50         NaN       3002.0       5002.0\n",
       "1       NaN     270.65  2012-09-10       3001.0       5003.0\n",
       "2   70002.0      65.26         NaN       3001.0          NaN\n",
       "3   70004.0     110.50  2012-08-17       3003.0       5001.0\n",
       "4       NaN     948.50  2012-09-10       3002.0          NaN\n",
       "5   70005.0    2400.60  2012-07-27       3001.0       5002.0\n",
       "6       NaN    5760.00  2012-09-10       3001.0       5001.0\n",
       "7   70010.0        NaN  2012-10-10       3004.0          NaN\n",
       "8   70003.0      12.43  2012-10-10          NaN       5003.0\n",
       "9   70012.0    2480.40  2012-06-27       3002.0       5002.0\n",
       "10      NaN     250.45  2012-08-17       3001.0       5003.0\n",
       "11  70013.0    3045.60  2012-04-25       3001.0          NaN"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result = df.replace({\"?\": np.nan, \"--\": np.nan})\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to drop the rows where at least one element is missing in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50  2012-10-05         3002       5002.0\n",
       "1       NaN     270.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26         NaN         3001       5001.0\n",
       "3   70004.0     110.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50  2012-09-10         3002       5002.0\n",
       "5   70005.0    2400.60  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43  2012-10-10         3004          NaN\n",
       "8   70003.0    2480.40  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,270.65,65.26,110.5,948.5,2400.6,5760,1983.43,2480.4,250.45, 75.29,3045.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ord_no  purch_amt    ord_date  customer_id  salesman_id\n",
       "0  70001.0     150.50  2012-10-05         3002       5002.0\n",
       "5  70005.0    2400.60  2012-07-27         3001       5001.0\n",
       "8  70003.0    2480.40  2012-10-10         3003       5003.0\n",
       "9  70012.0     250.45  2012-06-27         3002       5002.0"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result = df.dropna()\n",
    "# result = df.dropna(axis='columns')\n",
    "\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to drop the rows where all elements are missing in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id\n",
       "0       NaN        NaN         NaN          NaN\n",
       "1       NaN     270.65  2012-09-10       3001.0\n",
       "2   70002.0      65.26         NaN       3001.0\n",
       "3   70004.0     110.50  2012-08-17       3003.0\n",
       "4       NaN     948.50  2012-09-10       3002.0\n",
       "5   70005.0    2400.60  2012-07-27       3001.0\n",
       "6       NaN    5760.00  2012-09-10       3001.0\n",
       "7   70010.0    1983.43  2012-10-10       3004.0\n",
       "8   70003.0    2480.40  2012-10-10       3003.0\n",
       "9   70012.0     250.45  2012-06-27       3002.0\n",
       "10      NaN      75.29  2012-08-17       3001.0\n",
       "11  70013.0    3045.60  2012-04-25       3001.0"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[np.nan,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[np.nan,270.65,65.26,110.5,948.5,2400.6,5760,1983.43,2480.4,250.45, 75.29,3045.6],\n",
    "'ord_date': [np.nan,'2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[np.nan,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001]})\n",
    "\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Drop the rows where all elements are missing:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id\n",
       "1       NaN     270.65  2012-09-10       3001.0\n",
       "2   70002.0      65.26         NaN       3001.0\n",
       "3   70004.0     110.50  2012-08-17       3003.0\n",
       "4       NaN     948.50  2012-09-10       3002.0\n",
       "5   70005.0    2400.60  2012-07-27       3001.0\n",
       "6       NaN    5760.00  2012-09-10       3001.0\n",
       "7   70010.0    1983.43  2012-10-10       3004.0\n",
       "8   70003.0    2480.40  2012-10-10       3003.0\n",
       "9   70012.0     250.45  2012-06-27       3002.0\n",
       "10      NaN      75.29  2012-08-17       3001.0\n",
       "11  70013.0    3045.60  2012-04-25       3001.0"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nDrop the rows where all elements are missing:\")\n",
    "result = df.dropna(how='all')\n",
    "# print(\"\\nKeep the rows with at least 2 NaN values of the said DataFrame:\")\n",
    "# result = df.dropna(thresh=2)\n",
    "\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Pandas: Drop those rows in which specific columns have missing values\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"\\nDrop those rows in which specific columns have missing values:\")\n",
    "# result = df.dropna(subset=['ord_no', 'customer_id'])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to keep the valid entries of a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"\\nKeep the said DataFrame with valid entries:\")\n",
    "# result = df.dropna(inplace=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to calculate the total number of missing values in a DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id\n",
       "0       NaN        NaN         NaN          NaN\n",
       "1       NaN     270.65  2012-09-10       3001.0\n",
       "2   70002.0      65.26         NaN       3001.0\n",
       "3       NaN        NaN         NaN          NaN\n",
       "4       NaN     948.50  2012-09-10       3002.0\n",
       "5   70005.0    2400.60  2012-07-27       3001.0\n",
       "6       NaN    5760.00  2012-09-10       3001.0\n",
       "7   70010.0    1983.43  2012-10-10       3004.0\n",
       "8   70003.0    2480.40  2012-10-10       3003.0\n",
       "9   70012.0     250.45  2012-06-27       3002.0\n",
       "10      NaN      75.29  2012-08-17       3001.0\n",
       "11      NaN        NaN         NaN          NaN"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[np.nan,np.nan,70002,np.nan,np.nan,70005,np.nan,70010,70003,70012,np.nan,np.nan],\n",
    "'purch_amt':[np.nan,270.65,65.26,np.nan,948.5,2400.6,5760,1983.43,2480.4,250.45, 75.29,np.nan],\n",
    "'ord_date': [np.nan,'2012-09-10',np.nan,np.nan,'2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17',np.nan],\n",
    "'customer_id':[np.nan,3001,3001,np.nan,3002,3001,3001,3004,3003,3002,3001,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Total number of missing values of the said DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nTotal number of missing values of the said DataFrame:\")\n",
    "result = df.isna().sum().sum()\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to replace NaNs with a single constant value in specified columns in a DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>270.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>2400.60</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>2480.40</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50  2012-10-05         3002       5002.0\n",
       "1       NaN     270.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26         NaN         3001       5001.0\n",
       "3   70004.0     110.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50  2012-09-10         3002       5002.0\n",
       "5   70005.0    2400.60  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43  2012-10-10         3004          NaN\n",
       "8   70003.0    2480.40  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,270.65,65.26,110.5,948.5,2400.6,5760,1983.43,2480.4,250.45, 75.29,3045.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Replace NaNs with a single constant value:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0     70001.0\n",
       "1         0.0\n",
       "2     70002.0\n",
       "3     70004.0\n",
       "4         0.0\n",
       "5     70005.0\n",
       "6         0.0\n",
       "7     70010.0\n",
       "8     70003.0\n",
       "9     70012.0\n",
       "10        0.0\n",
       "11    70013.0\n",
       "Name: ord_no, dtype: float64"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nReplace NaNs with a single constant value:\")\n",
    "result = df['ord_no'].fillna(0, inplace=False)\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to replace NaNs with the value from the previous row or the next row in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Replacing NaNs with the value from the previous row (purch_amt):\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>150.50</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>948.50</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN     150.50     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0     948.50       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0    1983.43       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nReplacing NaNs with the value from the previous row (purch_amt):\")\n",
    "df['purch_amt'].fillna(method='pad', inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Replacing NaNs with the value from the next row (sale_amt):\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>150.50</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>11.50</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>948.50</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN     150.50     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26     11.50         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0     948.50     57.00  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0    1983.43     25.45  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nReplacing NaNs with the value from the next row (sale_amt):\")\n",
    "df['sale_amt'].fillna(method='bfill', inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to replace NaNs with median or mean of the specified columns in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using median in purch_amt to replace NaN:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>250.45</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN     250.45     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0     250.45       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0     250.45       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"Using median in purch_amt to replace NaN:\")\n",
    "df['purch_amt'].fillna(df['purch_amt'].median(), inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Using mean to replace NaN:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>250.45</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>39.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>39.00</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>39.00</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN     250.45     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26     39.00         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0     250.45     39.00  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0     250.45     39.00  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"Using mean to replace NaN:\")\n",
    "df['sale_amt'].fillna(int(df['sale_amt'].mean()), inplace=True)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to count the number of missing values of a specified column in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Missing values in purch_amt column:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nMissing values in purch_amt column:\")\n",
    "\n",
    "result= df['purch_amt'].value_counts(dropna=False).loc[np.nan]\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<bound method IndexOpsMixin.value_counts of 0      150.50\n",
       "1         NaN\n",
       "2       65.26\n",
       "3      110.50\n",
       "4      948.50\n",
       "5         NaN\n",
       "6     5760.00\n",
       "7     1983.43\n",
       "8         NaN\n",
       "9      250.45\n",
       "10      75.29\n",
       "11    3045.60\n",
       "Name: purch_amt, dtype: float64>"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['purch_amt'].value_counts"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to count the missing values in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Total missing values in a dataframe:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "ord_no         4\n",
       "purch_amt      3\n",
       "sale_amt       3\n",
       "ord_date       1\n",
       "customer_id    0\n",
       "salesman_id    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nTotal missing values in a dataframe:\")\n",
    "tot_missing_vals = df.isnull().sum()\n",
    "tot_missing_vals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tot_missing_vals.sum()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to find the Indexes of missing values in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Original Orders DataFrame:\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "print(\"Original Orders DataFrame:\")\n",
    "df\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "Missing values in purch_amt column:\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(array([ 1,  4,  6, 10], dtype=int64),)"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(\"\\nMissing values in purch_amt column:\")\n",
    "result = df['ord_no'].isnull().to_numpy().nonzero()\n",
    "result"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to replace the missing values with the most frequent values present in each column of a given dataframe.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [],
   "source": [
    "# print(\"\\nReplace the missing values with the most frequent values present in each column:\")\n",
    "# result = df.fillna(df.mode().iloc[0])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Write a Pandas program to create a hitmap for more information about the distribution of missing values in a given DataFrame.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ord_no</th>\n",
       "      <th>purch_amt</th>\n",
       "      <th>sale_amt</th>\n",
       "      <th>ord_date</th>\n",
       "      <th>customer_id</th>\n",
       "      <th>salesman_id</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>70001.0</td>\n",
       "      <td>150.50</td>\n",
       "      <td>10.50</td>\n",
       "      <td>2012-10-05</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>20.65</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>70002.0</td>\n",
       "      <td>65.26</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>70004.0</td>\n",
       "      <td>110.50</td>\n",
       "      <td>11.50</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3003</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>948.50</td>\n",
       "      <td>98.50</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>70005.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-07-27</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>NaN</td>\n",
       "      <td>5760.00</td>\n",
       "      <td>57.00</td>\n",
       "      <td>2012-09-10</td>\n",
       "      <td>3001</td>\n",
       "      <td>5001.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>70010.0</td>\n",
       "      <td>1983.43</td>\n",
       "      <td>19.43</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3004</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>70003.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012-10-10</td>\n",
       "      <td>3003</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>70012.0</td>\n",
       "      <td>250.45</td>\n",
       "      <td>25.45</td>\n",
       "      <td>2012-06-27</td>\n",
       "      <td>3002</td>\n",
       "      <td>5002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>75.29</td>\n",
       "      <td>75.29</td>\n",
       "      <td>2012-08-17</td>\n",
       "      <td>3001</td>\n",
       "      <td>5003.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>70013.0</td>\n",
       "      <td>3045.60</td>\n",
       "      <td>35.60</td>\n",
       "      <td>2012-04-25</td>\n",
       "      <td>3001</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     ord_no  purch_amt  sale_amt    ord_date  customer_id  salesman_id\n",
       "0   70001.0     150.50     10.50  2012-10-05         3002       5002.0\n",
       "1       NaN        NaN     20.65  2012-09-10         3001       5003.0\n",
       "2   70002.0      65.26       NaN         NaN         3001       5001.0\n",
       "3   70004.0     110.50     11.50  2012-08-17         3003          NaN\n",
       "4       NaN     948.50     98.50  2012-09-10         3002       5002.0\n",
       "5   70005.0        NaN       NaN  2012-07-27         3001       5001.0\n",
       "6       NaN    5760.00     57.00  2012-09-10         3001       5001.0\n",
       "7   70010.0    1983.43     19.43  2012-10-10         3004          NaN\n",
       "8   70003.0        NaN       NaN  2012-10-10         3003       5003.0\n",
       "9   70012.0     250.45     25.45  2012-06-27         3002       5002.0\n",
       "10      NaN      75.29     75.29  2012-08-17         3001       5003.0\n",
       "11  70013.0    3045.60     35.60  2012-04-25         3001          NaN"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import seaborn as sns\n",
    "import matplotlib.pyplot as plt\n",
    "pd.set_option('display.max_rows', None)\n",
    "#pd.set_option('display.max_columns', None)\n",
    "df = pd.DataFrame({\n",
    "'ord_no':[70001,np.nan,70002,70004,np.nan,70005,np.nan,70010,70003,70012,np.nan,70013],\n",
    "'purch_amt':[150.5,np.nan,65.26,110.5,948.5,np.nan,5760,1983.43,np.nan,250.45, 75.29,3045.6],\n",
    "'sale_amt':[10.5,20.65,np.nan,11.5,98.5,np.nan,57,19.43,np.nan,25.45, 75.29,35.6],\n",
    "'ord_date': ['2012-10-05','2012-09-10',np.nan,'2012-08-17','2012-09-10','2012-07-27','2012-09-10','2012-10-10','2012-10-10','2012-06-27','2012-08-17','2012-04-25'],\n",
    "'customer_id':[3002,3001,3001,3003,3002,3001,3001,3004,3003,3002,3001,3001],\n",
    "'salesman_id':[5002,5003,5001,np.nan,5002,5001,5001,np.nan,5003,5002,5003,np.nan]})\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAA5wAAAI/CAYAAAAbTdYlAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjMsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+AADFEAAAgAElEQVR4nO3dfbRsd13f8c+X3CAXEsNjU1RiWjEiQivmCloEg1IeqhWo2Ci6INRya0XQZauwSjVEfCCCi8qyKgeECNKQBp8gVA1SE5THXCBPPHhBCIEiCIJI5C5MyK9/zD5wOLln5j7M9547J6/XWmfdPXvPzP7NOfvOPu/Z+8zUGCMAAACwbLfZ7gEAAACwMwlOAAAAWghOAAAAWghOAAAAWghOAAAAWuzqX8V+b4MLAACwY51RWy1xhBMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWghMAAIAWuxZdoaruleRRSb4yyUjykSSvGmO8u3lsAAAArLC5Rzir6mlJXpGkkrw1yRXT9IVV9fT+4QEAALCqaoyx9cKq/Um+YYxx46b5t03yzjHG125xu71J9ibJC17wc2fu3Xv28kYMAADAceSM2mrJolNqb07yFUk+uGn+3adlBzXGWEuyNru0f+uiBQAAYMdaFJw/keR1VfXeJB+a5p2W5J5JfqxzYAAA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fq9mbm91jjPFnSX46s1OsTzrEoazH5bz1Hq6N29Qjk9xpCfd5XPFK85KMMd5eszfEWA+/F2XTIfExxl9Pr4S8KclfZ3b6zwlHsLrfT/KtSa7K7BWRnx5jfPTIRs42eneSJ0x/IP7eJL+R2fbzWzV7K/i3zLnti5KckeTqqroxyQuTHO5H7Pxykt+uqp9M8n8Pd/CZHeH6zao6kORbN5zuy/a7b5LnVNXNSW7M7G9+H53ZKUHXZXb62pcYY/xjzd7M4/lVdUpm+4f/kdnpaQfzM5ltox+c7vdwX3xYy2z7ffsY40iClWOsaT/340n+V1X9eGZ/l77u5UleXVX7klyZ5D3T/f9tzd4M5trMTn37qar6+iRvmjrihiQ/lORvjuaxcvTGGO+sql9IcnlVfT6z056fluQPq+qtmQXp+pHFs5L81LQ/uyHJ46f5X/I8sXn7G2O8YzpD51A8K7PntKun6LwuydBVWkcAAADbSURBVHcfwUP7jSQvmU73vjJe8D9Wlrlf25/kd6Z5leR5Y4y/q1u+59AtTNd74bz1HoHzklxYVW/P7M/krl/CfR5X6otHioFjZdpBXjLGuM82DwUAANo4pRYAAIAWjnAeB6rqGbnl37lcPMb4he0YDztLVT0xs9PWNnrDGOPJ2zEeVktV/c/c8rMUf3WM8ZLtGA+ryX6OVVBV982XvltyknxujPGA7RgPq6+qHp7k/E2zPzDGeMx2jGe7CE4AAABaOKUWAACAFoITAACAFoITAACAFoITAACAFv8f0LCRnIJAWuAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 1152x720 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(16,10))\n",
    "sns.heatmap(df.isnull(), cbar=False, cmap=\"YlGnBu\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
